//


#import "NT_HistoryDeleteViewController.h"
#import "NT_DeleTableViewCell.h"


@interface NT_HistoryDeleteViewController ()<UITableViewDelegate,UITableViewDataSource>
/** <#Description#>*/
@property (nonatomic, strong) UITableView *deleTableView;
/** <#Description#>*/
@property (nonatomic, strong) NSMutableArray *dataSource;
/** <#Description#>*/
@property (nonatomic, strong) NT_CoreDataBase *data;

@end

@implementation NT_HistoryDeleteViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    PostNotifition(@"Hidden");
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    PostNotifition(@"Appear");
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self setnavBatTitle:@"History"];
    _data = [[NT_CoreDataBase alloc]initWithCoreData:@"DeleData" modelName:@"NoteData" success:^{} fail:^(NSError * _Nullable error) {}];
    
    [self.view addSubview:self.deleTableView];
    [self getdeledata];
}
//#pragma mark ----------------- tableViewDelegate ----------------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"cellIdentifier";
    NT_DeleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[NT_DeleTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = _dataSource[indexPath.row];
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return kRelativeHeight(10);
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return nil;
}
//
#pragma mark ----------------- 懒加载 ----------------
- (UITableView *)deleTableView {
    if (!_deleTableView) {
        _deleTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, UI_NAV_BAR_HEIGHT, kMainScreenWidth, kMainScreenHeight - UI_NAV_BAR_HEIGHT) style:UITableViewStylePlain];
        _deleTableView.dataSource = self;
        _deleTableView.delegate   = self;
        _deleTableView.tableFooterView = [UIView new];
        _deleTableView.rowHeight  = kRelativeHeight(70);
    }
    return _deleTableView;
}
- (NSMutableArray *)dataSource {
    if (!_dataSource) {
        _dataSource = [NSMutableArray new];
    }
    return _dataSource;
}
//MARK:数据
- (void)getdeledata {
    //
    [_data ntReadEntity:nil ascending:NO filterStr:nil success:^(NSArray * _Nonnull results) {
        if (!results)return ;
        //
        self.dataSource = [results copy];
        [self.deleTableView reloadData];
        
    } fail:^(NSError * _Nullable error) {}];
    
}


/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
